import { store } from "@/store";
import { ref } from "vue";
import { defineStore } from "pinia";
import { UserInfo } from "@/types/user";
import { UserInfoEnum } from "@/enums/userInfo/user-info-enum";

export const useUserStore = defineStore("user", () => {
  // 用户信息
  const userInfo = ref<UserInfo>(UserInfoEnum);
  const setUserInfo = (val: UserInfo) => {
    userInfo.value = val;
  };
  const getUserInfo = () => {
    return userInfo.value;
  };
  return {
    userInfo,
    setUserInfo,
    getUserInfo,
  };
});

/**
 * 在组件外部使用UserStore的钩子函数
 * @see https://pinia.vuejs.org/core-concepts/outside-component-usage.html
 */
export function useUserStoreHook() {
  return useUserStore(store);
}
